package com.niit.drugsmanager.service.Impl;

import com.niit.drugsmanager.entity.AdministrativeRegion;
import com.niit.drugsmanager.repository.AdministrativeRegionRepository;
import com.niit.drugsmanager.service.AdministrativeRegionService;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Transactional
public class AdministrativeRegionServiceImpl implements AdministrativeRegionService {

    @Autowired
    private AdministrativeRegionRepository administrativeRegionRepository;

    @Override
    public AdministrativeRegion findAdministrativeRegionByCode(int code) {
        return administrativeRegionRepository.findByCode(code);
    }

    @Override
    public List<AdministrativeRegion> findAdministrativeRegionByLvl(int lvl) {
        return administrativeRegionRepository.findAllByLv(lvl);
    }

    @Override
    public List<AdministrativeRegion> findAllAdministrativeRegionsByParent(int parentId) {
        return administrativeRegionRepository.findAllByPcode(parentId);
    }

    @Override
    public AdministrativeRegion findAdministrativeRegionById(int id) {
        return administrativeRegionRepository.findById(id).orElse(null);
    }

    @Override
    public AdministrativeRegion findAdministrativeRegionByIdChain(String idChain) {
        return administrativeRegionRepository.findByIdChain(idChain);
    }
}
